import os
import uuid
class MyFiles:
    #指定文件操作目录
    def __init__(self,upload_dir='./static/upload/'):
        self.up_dir = upload_dir

    #创建文件夹
    def mk_dir(self,userid):
        path = self.up_dir+str(userid)+'/'
        #判断是否存在
        if not os.path.exists(path):
            os.mkdir(path)


    #文件重命名
    def rename(self,file):

        filename = uuid.uuid4().hex+str(os.path.splitext(file)[1])
        return filename
    #查找指定目录下的所有文件
    def show_all(self,userid):
        files = os.listdir(self.up_dir+str(userid)+'/')
        return files

    #删除文件
    def remove_files(self,userid,file):
        path = self.up_dir+str(userid)+'/'+file
        os.remove(path)

myf = MyFiles()
# myf.mk_dir(3)
# name = myf.rename('123123123.jpg')
# print(name)
# aa = myf.show_all(1)
# print(aa)
